package com.aispeech.asr.apis.ssc.config;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.alibaba.fastjson.JSON;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Configuration
@ConfigurationProperties(prefix = "apis.ssc")
@Data
@Slf4j
public class AppConfig {
    private String version;
    private boolean saveAudio;
    private String resRoot;
    private String vadRoot;
    private String vprUrl;
    private int compatibleResBuild;
    private int maxSize = 157286400;
    private String vadRes16k;
    private String vadRes8k;
    private String sscRes16k;
    private String sscRes8k;
    private String paragraphRes;
    private String cudaUnixpath;
    private int maxRetries = 1;
    private int nWorkers;
    
    private int nVprParallels = 8;
    private int queueSize;
    private long maxMinutes = 480;
    private long heartbeat = 1000L;
    
    
    public static int pcmBytesToMsecs(long offset, int sampleRate, int channel, int sampleBytes) {
        return (int) (offset * 1000 / (sampleRate * channel * sampleBytes));
    }
    
    public static long pcmMsecsToBytes(long duration, int sampleRate, int channel, int sampleBytes) {
        return duration * sampleRate * channel * sampleBytes / 1000;
    }
    
    private String vadRelationship;
    private Map<String, String> vadRelationshipMap = new HashMap<String,String>();
    
    
    @PostConstruct
    public void init() {
        //initVadRelationshipMap();
        initVadRelationshipMap2();
    }
    
    public Map<String, String> getVadRelationshipMap() {
        return vadRelationshipMap;
    }
    
    private void initVadRelationshipMap2() {
    	try {
    		vadRelationshipMap =  JSON.parseObject(vadRelationship, Map.class);
    	}catch(Exception e){
    		log.error("vadRelationship is not json String");
    	}
    	
    }
}
